//
//  RegisterViewController.m
//  ScoreManager
//
//  Created by 何凯楠 on 2017/4/19.
//  Copyright © 2017年 HeXiaoBa. All rights reserved.
//

#import "RegisterViewController.h"
#import "XTSqliteUtils.h"

@interface RegisterViewController ()
@property (weak, nonatomic) IBOutlet UITextField *nameField;
@property (weak, nonatomic) IBOutlet UITextField *passwordField;
@property (weak, nonatomic) IBOutlet UIButton *studentType;
@property (weak, nonatomic) IBOutlet UIButton *teacherType;

@end

@implementation RegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (IBAction)studentTypeClick:(UIButton *)sender {
    sender.selected = YES;
    self.teacherType.selected = NO;
}

- (IBAction)teacherTypeClick:(UIButton *)sender {
    sender.selected = YES;
    self.studentType.selected = NO;
}

- (IBAction)registerClick:(id)sender {
    
    NSString *username = self.nameField.text;
    NSString *password = self.passwordField.text;
    NSInteger type = self.studentType.selected ? 0 : 1;
    if (username.length == 0 || password.length == 0) {
        [self showAlertMsg:@"请填写用户名和密码"];
        return;
    }
    
    BOOL flag = [XTSqliteUtils insertUserWithUsename:username password:password type:type];
    if (flag) {
        [self.navigationController popViewControllerAnimated:YES];
    } else {
        [self showAlertMsg:@"注册失败"];
    }
    
}

- (void)showAlertMsg:(NSString *)msg {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:msg delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
    [alert show];
}



@end
